import { defaultListRequestParams } from '@/config';
import api from '@/services/shop/list-management';

export type ShopListManagement = ShopListManagementApi.InfoResponse;
export type ShopListManagementList = ShopListManagementApi.ListResponse;
export const getFilterList = async () => {
  const res = await api.getFilterList();
  return res.data;
};
export const getList = async (params: ShopListManagementApi.ListParams) => {
  const res = await api.getList<ShopListManagementList>(params);
  const tableData: Requestor.TableFormatedData<ShopListManagementList> = {
    data: res.listData,
    current: res.page + 1,
    pageSize: res.limit,
    total: res.count,
    success: res.success,
  };

  return tableData;
};
export const getAllList = async () => {
  const requestParams: ShopListManagementApi.ListParams = {
    ...defaultListRequestParams,
    page: 0,
    limit: 500,
  };
  const res = await api.getList<ShopListManagementList>(requestParams);
  return res.listData;
};
export const getInfo = async (params: ShopListManagementApi.InfoParams) => {
  const res = await api.getInfo<ShopListManagement>(params);
  return res.data;
};
export const create = async (params: ShopListManagementApi.CreateParams) => {
  const data = await api.create(params);
  return data;
};
export const update = async (params: ShopListManagementApi.UpdateParams) => {
  const data = await api.update(params);
  return data;
};
export const remove = async (params: ShopListManagementApi.DeleteParams) => {
  const data = await api.remove(params);
  return data;
};

export default {
  getFilterList,
  getList,
  getAllList,
  getInfo,
  create,
  update,
  remove,
};
